import Vue from 'vue'
import Router from 'vue-router'
import LoginPage from '@/views/login/login-page'
import IndexPage from '@/views/index/index-page'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    // {
    //   path: '/loading',
    //   name: 'loading',
    //   meta: {
    //     title: '登录'
    //   },
    //   component: () => import('@/views/loading/loading')
    // },
    {
      path: '/login',
      name: 'login-page',
      component: LoginPage,
      children: [
        {
          path: '/login',
          name: 'login',
          meta: {
            title: '登录'
          },
          component: () => import('@/views/login/login')
        },
        {
          path: '/login/login-sms',
          name: 'login-sms',
          meta: {
            title: '短信登录'
          },
          component: () => import('@/views/login/login-sms')
        },
        {
          path: '/login/registered-init',
          name: 'student-registration',
          meta: {
            title: '学员注册'
          },
          component: () => import('@/views/login/student-registration')
        }
      ]
    },
    {
      path: '/index',
      name: 'index-page',
      component: IndexPage,
      children: [
        {
          path: '/index',
          name: 'home',
          meta: {
            title: '首页'
          },
          component: () => import('@/views/index/home')
        },
        {
          path: '/index/more',
          name: 'more-class',
          meta: {
            title: '更多'
          },
          component: () => import('@/views/more/more-class')
        },
        {
          path: '/index/my-home',
          name: 'my-home',
          meta: {
            title: '我的'
          },
          component: () => import('@/views/my-home/my-home')
        },
        {
          path: '/index/my-courses',
          name: 'my-courses',
          meta: {
            title: '我的课程'
          },
          component: () => import('@/views/my-courses/my-courses')
        },
        {
          path: '/index/my-order',
          name: 'my-order',
          meta: {
            title: '我的订单'
          },
          component: () => import('@/views/my-order/my-order')
        },
        {
          path: '/index/course-detail',
          name: 'course-detail',
          meta: {
            title: '课程详情'
          },
          component: () => import('@/views/course-detail/course-detail')
        },
        {
          path: '/index/order-pay',
          name: 'order-payment',
          meta: {
            title: '提交订单'
          },
          component: () => import('@/views/order-payment/order-payment')
        },
        {
          path: '/reset-pass',
          name: 'reset-password',
          meta: {
            title: '修改密码'
          },
          component: () => import('@/views/login/reset-password')
        },
        {
          path: '/index/learning',
          name: 'learning',
          meta: {
            title: '在线学习'
          },
          component: () => import('@/views/learning/learning')
        }
      ]
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
